{if isset($fields) && !empty($fields)}
{assets css="filter"}

{assign var=fid value=$options.name|default:'filter'}
{assign var=fieldset_opened value=0}
{assign var=phrefix value=$fid}

<form action="{$options.action|default:'./'}" method="get" id="filter_{$fid}" class="filter {$options.class}">

{capture assign=out}
{foreach from=$fields key=k item=i}
{assign var=kid value=$k|replace:'[':''|replace:']':''}

{if isset($i.type)}

{if $i.type=='header'}
{if $fieldset_opened}</fieldset>{/if}
<fieldset>{if !isset($i.label)||mb_strlen($i.label)>0}<legend>{$i.label|default:$k|translate}</legend>{/if}
{assign var=fieldset_opened value=$fieldset_opened+1}
{else}


{if (!isset($i.label)||mb_strlen($i.label)) && $i.type!='check' && $i.type!='label'}<label class="{$i.type}" for="filter{$fid}_{$kid}">{$i.label|default:$k|translate}</label>{/if}

{if $i.type=='label'}
<label class="radio">{$i.value}</label>
{elseif $i.type=='list'}
<select id="filter{$fid}_{$kid}" name="{$phrefix}[{$k}]" class="  msgPos:'filter{$fid}_{$kid}_info' {$i.class|default:''}" {if @$i.readonly||@$options.mode.readonly}disabled=""{/if}>
{if isset($i.null) && $i.null}<option value="0" title="&mdash;">&mdash;</option>{/if}
{foreach from=$i.values item=vi key=vk}
<option {if isset($i.value) && $i.value==$vi.id}selected="selected"{/if} value="{$vi.id}" title="{$vi.title|default:''|escape}">{$vi.title|default:''}</option>
{/foreach}
</select>

{elseif $i.type=='radio'}
{if isset($i.null) && $i.null}
<input type="radio" id="filter{$fid}_{$kid}_null" name="{$phrefix}[{$kid}]" value="" title="&mdash;" {if !isset($i.value)||$i.value===''}checked="checked"{/if} />
<label class="radiovalue">&mdash;</label>
{/if}
{foreach from=$i.values item=vi key=vk}
<input type="radio" id="filter{$fid}_{$kid}_{$vk}" name="{$phrefix}[{$kid}]" value="{$vi.id}" {if isset($i.value) && $i.value==$vi.id}checked="checked"{/if} value="{$vi.id}" title="{$vi.title|default:''|escape}" />
<label class="radiovalue" for="filter{$fid}_{$kid}_{$vk}">{$vi.title|default:''|translate}</label>
{/foreach}

{elseif $i.type=='check'}
{*<input name="{$phrefix}[{$k}]" type="hidden" value="" />*}
<input id="filter{$fid}_{$kid}" name="{$phrefix}[{$k}]" type="checkbox" class="validate-{$i.type}  msgPos:'filter{$fid}_{$kid}_info' {$i.class|default:''}" value="1" {if $i.value>0}checked="checked"{/if} autocomplete="off" />
<label class="check" for="filter{$fid}_{$kid}">{$i.label|default:$k|translate}</label>

{elseif $i.type=='date' || $i.type=='time' || $i.type=='datetime'}
{capture assign=_attrs}type="text" class="iMask validate-{$i.type} msgPos:'filter{$fid}_{$kid}_info' {$i.class|default:''} dateFormat:'{$i.type|replace:"date":"%d.%m.%Y"|replace:"time":", %H:%M"|@trim:", "}'" alt="{ldelim}'type':'fixed','mask':'{$i.type|replace:"date":"99.99.9999"|replace:"time":", 99:99"|@trim:", "}','stripMask':false{rdelim}" autocomplete="{if @$i.autocomplete}on{else}off{/if}"{/capture}
{if $i.period}
<input id="filter{$fid}_{$kid}" name="{$phrefix}[{$k}][from]" value="{$i.value.from|default:''|escape}" {$_attrs} /><input id="filter{$fid}_{$kid}" name="{$phrefix}[{$k}][to]" value="{$i.value.to|default:''|escape}" {$_attrs} />
{else}
<input id="filter{$fid}_{$kid}" name="{$phrefix}[{$k}]" value="{$i.value|default:''|escape}" {$_attrs} />
{/if}

{elseif $i.type=='month'}
<input id="filter{$fid}_{$kid}" name="{$phrefix}[{$k}]" type="text" class="iMask validate-{$i.type} msgPos:'filter{$fid}_{$kid}_info' {$i.class|default:''} dateFormat:'%m.%Y'" value="{$i.value|default:''|escape}" alt="{ldelim}'type':'fixed','mask':'99.9999','stripMask':false{rdelim}" autocomplete="{if @$i.autocomplete}on{else}off{/if}" />

{elseif $i.type=='phone'}
<input id="filter{$fid}_{$kid}" name="{$phrefix}[{$k}]" type="text" class="iMask validate-{$i.type} msgPos:'filter{$fid}_{$kid}_info' {$i.class|default:''}" value="{$i.value|trim:'+'|default:''|escape}" alt="{ldelim}'type':'fixed','mask':'+9 999 999-9999','stripMask':true{rdelim}" autocomplete="{if @$i.autocomplete}on{else}off{/if}" />
{else}
<input id="filter{$fid}_{$kid}" name="{$phrefix}[{$k}]" type="text" class="{if isset($i.mask)}iMask{/if}  {if isset($i.fixedLength)}fixedLength:{$i.fixedLength}{/if} msgPos:'filter{$fid}_{$kid}_info' {$i.class|default:''}" value="{$i.value|default:''|escape}" {if isset($i.mask)}alt="{ldelim}'type':'fixed','mask':'{$i.mask|escape}','stripMask':true{rdelim}"{/if} autocomplete="{if @$i.autocomplete}on{else}off{/if}" />
{/if}

{/if}
{/if}
{/foreach}

{if $fieldset_opened>1}</fieldset>{/if}
<input type="submit" value="{$options.submit|default:'Фильтровать'}" class="btn-submit" />
<input type="reset"  value="{$options.reset|default:'Сбросить'}" class="btn-reset" />
<input type="button" value="{$options.clear|default:'Убрать'}" class="btn-clear" onclick="javascript:window.location='./';" />
{if $fieldset_opened==1}</fieldset>{/if}
{/capture}


{* render fieldset if not set *}
{if !$fieldset_opened}
<fieldset><legend>{$options.label|default:$options.name|translate}</legend>{$out}</fieldset>
{else}
{$out}
{/if}

</form>
{/if}
